//
//  CellOfNews.m
//  王宇先_13
//
//  Created by wyx on 16/3/25.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "CellOfNews.h"
#import "ModleOfContact.h"

#pragma mark - 宏
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

#pragma mark - 声明
@interface CellOfNews()
@property (retain, nonatomic) IBOutlet UIImageView *imageOfPic;
@property (retain, nonatomic) IBOutlet UILabel *lableOfTitle;
@property (retain, nonatomic) IBOutlet UILabel *lableOfDate;
@property (retain, nonatomic) IBOutlet UILabel *lableOfSummary;
@end



@implementation CellOfNews
#pragma mark - delloac
- (void)dealloc {
    [_imageOfPic release];
    [_lableOfTitle release];
    [_lableOfDate release];
    [_lableOfSummary release];
    [super dealloc];
}

#pragma mark - 子控件赋值
- (void)setCellContentValue:(ModleOfContact *)model{
    //子控件赋值
    self.imageOfPic.image = [UIImage imageNamed:@"1.jpg"];
    //调用时间格式转换方法
    self.lableOfDate.text = [self dateFormatReverseWithTimeIntervale:model.lastUpdateTime];
    self.lableOfTitle.text = model.title;
    self.lableOfSummary.text = model.summary;
    self.lableOfTitle.numberOfLines = 0;
    self.lableOfSummary.numberOfLines = 0;
    self.lableOfDate.textAlignment = 2;

    
}
#pragma mark - 时间格式的转换 详见 API: NSDate
- (NSString *)dateFormatReverseWithTimeIntervale:(NSString *)timeInterval {
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInterval.doubleValue];
    //格式转化
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *formattedDateString = [dateFormatter stringFromDate:date];
    return formattedDateString;
}
#pragma mark - 计算 新的矩形   Cell 高度
+ (CGFloat)heightOfCellNews:(NSString *)text{
    CGFloat width = [UIScreen mainScreen].bounds.size.width - 10;
    CGRect newRect = [text boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    return newRect.size.height + 175 + 15;
}
#pragma mark - other
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
@end
